from flask import Flask, render_template, request, session, jsonify
# from flask_sqlalchemy import SQLAlchemy
from config import Config, db
from flask_bootstrap import Bootstrap

# from flask_session import Session


app = Flask(__name__, template_folder='templates')  # 同名会优先使用根目录的templates
app.config.from_object(Config)
# app.DEBUG = True
# mysql://myname:123456@127.0.0.1:3306/mydatabase  连接基本形式： 别名+驱动://用户名:密码@主机:端口/数据库
# app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///datas/pms.db'
# app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
# app.config['SQLALCHEMY_ECHO'] = True
# db = SQLAlchemy(app)


bootstrap = Bootstrap(app)
# 把app加载到db对象中
db.init_app(app)

# Session(app)

# 注册蓝图
from app1 import app1_blue

app.register_blueprint(app1_blue, url_prefix='/app1')

from login import login_blue

app.register_blueprint(login_blue, url_prefix='/login')


@app.route('/bootstrap')
def bootstrap():
    return render_template('bootstrap_index.html')


@app.route('/create_models')
def create_models():
    """建立 Models数据表"""
    from .models import BaseModel, Goods
    # db.init_app(app)
    db.create_all()
    return "Models 数据创建完成！"


@app.route('/')
def index():
    print(app.url_map)
    # return 'test ok,url_map详情已在后台打印'
    #                    返回的信息，           给浏览器的状态码   给浏览器的头不信息
    return jsonify({'code': 201, 'msg': '登陆成功'}), 201, {'Etag': 'some-opaque-string'}


if __name__ == '__main__':
    app.run()
